package com.wang.API;

import com.wang.bean.Appedtion;
import com.wang.bean.Result;

import com.wang.bean.Verupdatelog;
import com.wang.service.AppedtionService;
import com.wang.service.VerupdatelogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 *
 import requests
 import hashlib
 import time

 url = "http://127.0.0.1:8080/api/functionlist"

 files = {'file':open('e:\\1.jpg','rb')}

 data = {'type':'multipart/form-data','name':'wang'}

 reponse = requests.post(url,data=data,files=files)

 text = reponse.text

 print ("text:"+text)

 */


@RestController
@RequestMapping("api")
public class AppedtionController {

    @Autowired
    private AppedtionService appedtionService;

    @Autowired
    private VerupdatelogService verupdatelogService;

    @RequestMapping("/appedtionlistall")
    public Result appedtionlistall()
    {
        List<Appedtion> list = appedtionService.listAll();
        Result re=new Result();
        re.setCode("611");
        re.setData(list);
        return re;
    }

    @RequestMapping("/appedtionlist")
    public Result appedtionlist()
    {
        List<Appedtion> list = appedtionService.list();
        Result re=new Result();
        re.setCode("612");
        re.setData(list);
        return re;
    }

    @RequestMapping("/appedtionlastedtion")
    public Result appedtionlastedtion()
    {
        Appedtion edtion = appedtionService.getlastedtion();
        Result re=new Result();
        re.setCode("612");
        re.setData(edtion);
        return re;
    }


    //显示版本更新日志

    @RequestMapping("/verupdateloglist")
    public Result verupdateloglist()
    {
        List<Verupdatelog> list = verupdatelogService.list();
        Result re=new Result();
        re.setCode("612");
        re.setData(list);
        return re;
    }

    //记录日志
    @RequestMapping("/verloginsert")
    public Result verloginsert(HttpServletRequest servletRequest)
    {
        Verupdatelog ver=new Verupdatelog();
        ver.setCurrentver(servletRequest.getParameter("currentver"));
        ver.setUpdatever(servletRequest.getParameter("updatever"));
        ver.setDevicebrand(servletRequest.getParameter("devicebrand"));
        ver.setSystemmodel(servletRequest.getParameter("systemmodel"));
        ver.setSystemversion(servletRequest.getParameter("systemversion"));
        ver.setGps(servletRequest.getParameter("gps"));
        ver.setLicense(servletRequest.getParameter("license"));
        verupdatelogService.verupdateloginsert(ver);
        Result re=new Result();
        re.setCode("613");
        return re;
    }







 }
